<?php

/**
 * This is the model class for table "Artiste".
 *
 * The followings are the available columns in table 'Artiste':
 * @property integer $id_client
 * @property string $description
 * @property string $paiement
 * @property string $siteweb
 * @property string $facebook
 * @property string $twitter
 * @property string $cgv
 * @property string $valid
 * @property integer $id_virement
 * @property integer $id_paypal
 *
 * The followings are the available model relations:
 * @property Client $client
 * @property Produit[] $produits
 */
class Artiste extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Artiste the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'Artiste';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('id_client, description, paiement, cgv, valid', 'required'),
			array('id_client, id_virement, id_paypal', 'numerical', 'integerOnly'=>true),
			array('description, siteweb, facebook, twitter', 'length', 'max'=>500),
			array('paiement', 'length', 'max'=>8),
			array('cgv, valid', 'length', 'max'=>1),
			array('cgv', 'required', 'requiredValue'=>1, 'message'=>'Vous devez accepter les conditions générales de ventes.'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id_client, description, paiement, siteweb, facebook, twitter, cgv, valid, id_virement, id_paypal', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'client' => array(self::BELONGS_TO, 'Client', 'id_client'),
			'produits' => array(self::HAS_MANY, 'Produit', 'id_artiste'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id_client' => 'Id Client',
			'description' => 'Description',
			'paiement' => 'Mode de paiement',
			'siteweb' => 'Site web personnel',
			'facebook' => 'Facebook',
			'twitter' => 'Twitter',
			'cgv' => 'Conditions générales de vente',
			'valid' => 'Valid',
			'id_virement' => 'Id Virement',
			'id_paypal' => 'Id Paypal',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id_client',$this->id_client);
		$criteria->compare('description',$this->description,true);
		$criteria->compare('paiement',$this->paiement,true);
		$criteria->compare('siteweb',$this->siteweb,true);
		$criteria->compare('facebook',$this->facebook,true);
		$criteria->compare('twitter',$this->twitter,true);
		$criteria->compare('cgv',$this->cgv,true);
		$criteria->compare('valid',$this->valid,true);
		$criteria->compare('id_virement',$this->id_virement);
		$criteria->compare('id_paypal',$this->id_paypal);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
	public static function getTroisDerniersArtistes () {
		$criteria = new CDbCriteria;
		$criteria->limit = 3;
		return Artiste::model()->findAll($criteria);
	}
}